package cn.liuwenlin.mq.activemqspringboot.listener;

import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.stereotype.Service;

@Service
public class Receiver {

    @Autowired
    private JmsMessagingTemplate messagingTemplate;

    @JmsListener(destination = "springboot", containerFactory = "jmsListenerContainerTopic")
    public void recvFromTopic(String msg){
        System.out.println("receive topic msg: " + msg);
    }

    @JmsListener(destination = "activemq", containerFactory = "jmsListenerContainerTopic")
    public void recvFromTopic2(String msg){
        System.out.println("receive topic msg: " + msg);
    }

    @JmsListener(destination = "activemq", containerFactory = "jmsListenerContainerQueue")
    public void recvFromQueue(String msg){
//        Object result = messagingTemplate.receiveAndConvert(Object.class);
        System.out.println("receive queue msg: " + msg);
    }

}
